package com.roc.web.action.terminal;

import java.util.ArrayList;
import java.util.List;

import com.roc.page.BaseSearchCondition;
import com.roc.page.WhereHQLFieldBean;
import com.roc.util.Constance;

/**
 * 
 * @author fupan
 * 
 * 终端序列号查询
 * 
 * 2014-08-18
 *
 */
public class TermSnQuerySearchCondition extends BaseSearchCondition {
	

	private String orgCode;
//	private String agentId;
	private String posBrand;  //品牌
	private String posType;  //机型
	private String posName; //POS名称
	private String isBind;
//	private String isUsed;
	private String serialNum;//
	private String realName;//代理商名称

	private String accountNo;
	
//	private String[] agentIdList;//下级代理商
	

	private String obj;//代理商id
	
	private String opId; // 业务员
	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getOrderPartOfHQL()
	 */
	@Override
	protected String getOrderPartOfHQL() {
		// TODO Auto-generated method stub
		
		return " order by i.dt_create desc ";
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getRowCountHQL()
	 */
	@Override
	protected String getRowCountHQL() {//,OrgBean o  t.orgCode = o.org_code
		StringBuffer sb=new StringBuffer();
		sb.append(" SELECT COUNT(*) ");
		sb.append(" FROM yj_pos_info i ");
		sb.append(" , T_OPERATORS o ");
		
		sb.append(" where o.account_no = i.OPERATORS and i.is_bind = 'N' and i.OPERATORS =  '" + accountNo + "'");
		
		return sb.toString();
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getSearchHQL()
	 */
	@Override
	protected String getSearchHQL() {
		StringBuffer sb=new StringBuffer();
		sb.append(" SELECT i.serial_num,i.pos_brand,i.pos_type,i.pos_name,i.org_code,i.is_bind,i.MERC_CODE,i.TERM_CODE,i.REMARK,i.DT_CREATE,i.DT_LASTMOD,o.REAL_NAME,i.OPERATORS,i.tek_id ");
		sb.append(" FROM yj_pos_info i ");
		sb.append(" , T_OPERATORS o ");
		sb.append(" where o.account_no = i.OPERATORS and i.is_bind = 'N' and i.OPERATORS =  '" + accountNo + "'");
		
		return sb.toString(); //y.isBind = 'N'
	}

	/* (non-Javadoc)
	 * @see com.roc.page.BaseSearchCondition#getWhereHQLFieldBeanList()
	 */
	@Override
	protected List<WhereHQLFieldBean> getWhereHQLFieldBeanList() {
		List<WhereHQLFieldBean> filedBeanList = new ArrayList<WhereHQLFieldBean>();

		
		if (Constance.isNotEmpty(orgCode)) {
			filedBeanList.add(new WhereHQLFieldBean("i.org_code", orgCode, "=", false));
		}

		if (Constance.isNotEmpty(posBrand) && !posBrand.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("i.pos_brand", posBrand, "=", false));
		}
		if (Constance.isNotEmpty(posType) && !posType.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("i.pos_type", posType, "=", false));
		}
		if (Constance.isNotEmpty(posName) && !posName.equals("-1")) {
			filedBeanList.add(new WhereHQLFieldBean("i.pos_name", posName, "=", false));
		}/*
		if (Constance.isNotEmpty(agentId)) {
			filedBeanList.add(new WhereHQLFieldBean("i.agent_id", agentId, "=", false));
		}*/
		/*if (Constance.isNotEmpty(isBind) && !isBind.equals("99")) {
			filedBeanList.add(new WhereHQLFieldBean("i.is_bind", isBind, "=", false));
		}*//*
		if (Constance.isNotEmpty(isUsed) && !isUsed.equals("99")) {
			filedBeanList.add(new WhereHQLFieldBean("a.is_used", isUsed, "=", false));
		}*/
		if (Constance.isNotEmpty(serialNum) && !serialNum.equals("")) {
			filedBeanList.add(new WhereHQLFieldBean("i.serial_num", serialNum, "=", false));
		}
		if(Constance.isNotEmpty(realName)){
			filedBeanList.add(new WhereHQLFieldBean("o.REAL_NAME", realName.trim(), "like", false,"ALL"));
		}
		if (Constance.isNotEmpty(opId)) {
			filedBeanList.add(new WhereHQLFieldBean("i.AGENT_ID", opId
					.trim().trim(), "=", false));
		}
		
		/*
		if(agentIdList!=null&&agentIdList.length >0){//下级代理商
        	filedBeanList.add(new WhereHQLFieldBean("a.agent_id IN("+Constance.getArrayContent(agentIdList)+")"));
        }*/
		
		return filedBeanList;
	}


	public String getOrgCode() {
		return orgCode;
	}

	public void setOrgCode(String orgCode) {
		this.orgCode = orgCode;
	}

	public String getPosBrand() {
		return posBrand;
	}

	public void setPosBrand(String posBrand) {
		this.posBrand = posBrand;
	}

	public String getPosType() {
		return posType;
	}

	public void setPosType(String posType) {
		this.posType = posType;
	}

	public String getPosName() {
		return posName;
	}

	public void setPosName(String posName) {
		this.posName = posName;
	}
/*
	public String getAgentId() {
		return agentId;
	}

	public void setAgentId(String agentId) {
		this.agentId = agentId;
	}*/

	public String getIsBind() {
		return isBind;
	}

	public void setIsBind(String isBind) {
		this.isBind = isBind;
	}
/*
	public String getIsUsed() {
		return isUsed;
	}

	public void setIsUsed(String isUsed) {
		this.isUsed = isUsed;
	}*/

	public String getSerialNum() {
		return serialNum;
	}

	public void setSerialNum(String serialNum) {
		this.serialNum = serialNum;
	}

	public String getRealName() {
		return realName;
	}

	public void setRealName(String realName) {
		this.realName = realName;
	}

	public String getObj() {
		return obj;
	}

	public void setObj(String obj) {
		this.obj = obj;
	}

	public String getOpId() {
		return opId;
	}

	public void setOpId(String opId) {
		this.opId = opId;
	}

	public String getAccountNo() {
		return accountNo;
	}

	public void setAccountNo(String accountNo) {
		this.accountNo = accountNo;
	}
	
}
